package com.example.campuslink.commen.adpter

import android.widget.TextView
import com.example.campuslink.BR
import com.example.campuslink.R
import com.example.campuslink.commen.core.CoreAdapter
import com.example.campuslink.commen.core.CoreViewHolder
import com.example.campuslink.databinding.AdapterHotSearchBinding
import com.example.campuslink.model.SearchWordData
import com.example.campuslink.viewModel.search.SearchMainViewModel

class HotSearchAdapter(vm: SearchMainViewModel) :
    CoreAdapter<AdapterHotSearchBinding, SearchMainViewModel, SearchWordData>(
        BR.data,
        BR.viewModel,
        vm
    ) {
    override fun getItemLayoutId(viewType: Int): Int {
        return R.layout.adapter_hot_search
    }

    override fun onBindViewHolder(holder: CoreViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        holder.binding.root.findViewById<TextView>(R.id.tv_search_word).text =
            mListData[position].searchWord
        holder.binding.root.findViewById<TextView>(R.id.tv_id).text =
            "${position + 1}"
        holder.binding.root.findViewById<TextView>(R.id.tv_hot).text =
            mListData[position].searchCount.toString()
        holder.binding.root.setOnClickListener({
            mViewModel?.addSearchInfo(mListData[position].searchWord)
            mViewModel?.jumpToSearchResult(mListData[position].searchWord)
        })
    }
}